﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.ComponentModel;
using System.Globalization;
using System.Reflection;
using System.Security.Policy;

namespace Lilium.Configuration
{
	public sealed class AssemblyNameConverter: ConfigurationConverterBase
	{
		public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
		{
			var assemblyName = value as string;
			if (!string.IsNullOrEmpty(assemblyName))
				return Assembly.Load(assemblyName);
			else
				return base.ConvertFrom(context, culture, value);
		}

		public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
		{
			var assembly = value as Assembly;
			if ((assembly != null) && (destinationType == typeof(string)))
				return assembly.FullName;
			else
				return base.ConvertTo(context, culture, value, destinationType);
		}
	}
}
